package activity;


import hcs.model.Clock;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

/**
 * 
 * @author vincenzo.delia@polito.it
 *
 */
public class SetClockActivity {
	static private Timer t;
	static private int delay;
	
	private ActionListener tic = new ActionListener() {
		public void actionPerformed(ActionEvent evt) {
	          Clock.getInstance().tic();;
	      }
	};
	
	public void start() {
		if(t != null && t.isRunning())
			t.stop();
		t = new Timer(SetClockActivity.delay, tic);
		t.start();
	}
	
	public void stop() {
		t.stop();
	}
	
	public void setDelay(int delay) {
		SetClockActivity.delay = delay;
		if(t!=null && t.isRunning()) {
			t.stop();
			this.start();
		}
	}
	
	public int geDelay() {
		return delay;
	}
}
